package com.atguigu.distributed.lock.leecode.greedy;

/**
 * 力扣中等45跳跃游戏
 */
public class JumpGame2 {
    public static void main(String[] args) {
        JumpGame2 test = new JumpGame2();
        int[] nums = {2,3,0,1,4};
        System.out.println(test.jump(nums));
    }
    public int jump(int[] arr){
        int end = 0;
        int maxPosition = 0;
        int step = 0;
        for (int i = 0; i < arr.length-1;i++) {
            maxPosition = Math.max(maxPosition,i+arr[i]);
            if(i==end){
                end = maxPosition;
                step++;
            }

        }
        return step;
    }
}
